<?php

/**
 * ECSHOP 程序说明
 * ===========================================================
 * 版权所有 2005-2010 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ==========================================================
 * $Author: liuhui $
 * $Id: flashplay.php 17063 2010-03-25 06:35:46Z liuhui $
 */

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
include_once(ROOT_PATH . '/includes/cls_ftp.php');
$upload = new ftp_upload();
$type = 'main_flash';

if(empty($_REQUEST['act'])){
	$_REQUEST['act'] = 'list';
}
if($_REQUEST['act'] == 'list'){
	$list = $db->getAll("SELECT id,title,link,sort_order,pic FROM ".$ecs->table("relation_pic")." ORDER BY sort_order ASC,id DESC");
	$smarty->assign('list', $list);
	$smarty->assign('action_link', array('text'=>'添加图片', 'href'=>'flashplay.php?act=add'));
	$smarty->display("flashplay_list.htm");
}elseif($_REQUEST['act'] == 'add'){
	$rt = array(
		'act' => 'insert',
		'sort_order' => 5,
		'id'=>0
	);
	$smarty->assign('rt', $rt);
	$smarty->assign('action_link', array('text'=>'图片列表', 'href'=>'flashplay.php?act=list'));
	$smarty->display("flashplay_add.htm");
}elseif($_REQUEST['act'] == 'delete'){
	$row = $db->getOne("SELECT pic FROM ".$ecs->table("relation_pic")." WHERE id=".intval($_GET['id']));
	$db->query("DELETE FROM ".$ecs->table("relation_pic")." WHERE id=".intval($_GET['id']));
	add_delete_img($row);
	 $link[0]['href']='flashplay.php?act=list';
    $link[0]['text']='返回图片列表';
	sys_msg('删除成功！', 0, $link);
}elseif($_REQUEST['act'] == 'edit'){
	$rt = $db->getRow("SELECT * FROM ".$ecs->table("relation_pic")." WHERE id=".intval($_GET['id']));
	$rt['act'] = 'update';
	$smarty->assign('rt', $rt);
	$smarty->assign('action_link', array('text'=>'图片列表', 'href'=>'flashplay.php?act=list'));
	$smarty->display("flashplay_add.htm");
}elseif($_REQUEST['act'] == 'insert'){
	$pic='';
	if (isset($_FILES['pic']) && $_FILES['pic']['tmp_name'] != '' &&
        isset($_FILES['pic']['tmp_name']) &&$_FILES['pic']['tmp_name'] != 'none')
    {
    	$file = $upload->upLoadFileOne($_FILES['pic'], 'pic');
        if($file!==false){
        	$pic = $file['url'];
        }else{
        	sys_msg($upload->getError());
        }
    }
    $sort_order = isset($_POST['sort_order']) ? intval($_POST['sort_order']) : 5;
    $sql = "INSERT INTO ".$ecs->table("relation_pic")." SET ".
    	" `type`='$type', `title`='{$_POST['title']}', `link`='{$_POST['link']}', `pic`='$pic', `sort_order`='$sort_order', `add_time`='".time()."'";
    $db->query($sql);
    $link[0]['href']='flashplay.php?act=list';
    $link[0]['text']='返回图片列表';
    $link[1]['href']='flashplay.php?act=add';
    $link[1]['text']='继续添加图片';
    sys_msg('图片添加成功！', 0, $link);
}elseif($_REQUEST['act'] == 'update'){
	$pic='';
	if (isset($_FILES['pic']) && $_FILES['pic']['tmp_name'] != '' &&
        isset($_FILES['pic']['tmp_name']) &&$_FILES['pic']['tmp_name'] != 'none')
    {
    	$file = $upload->upLoadFileOne($_FILES['pic'], 'pic');
        if($file!==false){
        	$pic = $file['url'];
        }else{
        	sys_msg($upload->getError());
        }
    }
    $sort_order = isset($_POST['sort_order']) ? intval($_POST['sort_order']) : 5;
    
    $sql = "UPDATE ".$ecs->table("relation_pic")." SET ".
    	"`title`='{$_POST['title']}', `link`='{$_POST['link']}', `sort_order`='$sort_order'";
    if($pic){
    	$sql .= ",pic='$pic' ";
    }
    $sql .= " WHERE id=".intval($_POST['id']);
    $db->query($sql);
    $link[0]['href']='flashplay.php?act=list';
    $link[0]['text']='返回图片列表';
    sys_msg('图片修改成功！', 0, $link);
}
?>